package com.train.course.controller;

import com.train.common.annotation.Anonymous;
import com.train.common.core.domain.AjaxResult;
import com.train.course.domain.VideoCategory;
import com.train.course.dto.QueryDTO;
import com.train.course.mapper.VideoCourseMapper;
import com.train.course.service.VideoCourseCategoryService;
import com.train.course.vo.QueryVideoCourseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/category")
public class VideoCourseCategoryController {
    @Autowired
    private VideoCourseMapper videoCourseMapper;


    @Autowired
    private VideoCourseCategoryService videoCourseCategoryService;


    /**
     * 查询所有正常状态的视频分类列表
     */
    @Anonymous
    @GetMapping("/listNormal")
    public AjaxResult listNormal()
    {
        List<VideoCategory> videoCategories = videoCourseMapper.selectNormalVideoCategoryList();

        return AjaxResult.success(videoCategories);
    }

    @Anonymous
    @PostMapping("/query/course")
    public AjaxResult listCourseByCategoryId(@RequestBody QueryDTO queryDTO)
    {
        if (queryDTO == null || queryDTO.getCategoryId() == null){
            return AjaxResult.error("参数错误");
        }
        log.info("用户通过分类id查询课程");
        QueryVideoCourseVO queryVideoCourseVO = videoCourseCategoryService.queryCourseByCategoryId(queryDTO);
        return AjaxResult.success(queryVideoCourseVO);

    }
}
